<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:decorate template="/resources/template/modelo.xhtml">

        <ui:define name="centro">
            <f:view encoding="ISO-8859-1">  
                <h:form id="form">
                    <p:messages id="messages1" showDetail="true" autoUpdate="true" closable="true" escape="false" /> 
                    <p:panel id="pInfBasicas"  header="Cadastro de Disciplinas de GS" style="width: 95%;background-color: #E0E0E0" >
                        <div algin="center" >
                            <h:panelGrid columns="2" width="99%" style="text-align: center" >
                                <h:outputText value="Nome da Disciplina: " style="width: 20%" />
                                <p:inputText value="#{disciplinaGSBean.disciplina.nome}" style="width: 80%" /> 
                                <h:outputText value="Carga Horária: " style="width: 20%" />
                                <p:inputText value="#{disciplinaGSBean.disciplina.cargaHoraria}" maxlength="3" style="width: 80%" /> 
                                <h:outputText value="Curso:" style="width: 20%" />
                                <p:selectOneMenu value="#{disciplinaGSBean.disciplina.curso.id}" style="width:80%"  
                                                 effect="fade"  filter="true" filterMatchMode="startsWith" >  
                                    <f:selectItem itemLabel="Selecione" itemValue="" noSelectionOption="true"  />  
                                    <f:selectItems value="#{cursoBean.cursos}" var="c" itemLabel="#{c.nome}- #{c.tipologia} -  #{c.instituicao.nome},  #{c.instituicao.estado} - #{c.instituicao.estado}" itemValue="#{c.id}" />
                                </p:selectOneMenu> 



                            </h:panelGrid>

                            <p:panel id="pProducao"  header="Sobre a Produção" style="width: 95%;background-color: #A0A0A0" >
                                <h:panelGrid columns="2" width="99%" style="text-align: center" >
                                    <h:outputText value="Ano de Início da Oferta: " style="width: 20%" /> 
                                    <p:inputText value="#{disciplinaGSBean.disciplina.anoCriacao}" style="width: 80%" /> 
                                </h:panelGrid>
                                <h:panelGrid columns="1" width="99%" style="text-align: center" >
                                    <h:outputText value="Metodologia (Máximo de 1000 caracteres): " style="width: 100%" /> 
                                    <p:editor value="#{disciplinaGSBean.disciplina.metodologia}" width="800" maxlength="1000" /> 
                                    <h:outputText value="Bibliografia Principal (Máximo de 1000 caracteres): " style="width: 100%" /> 
                                    <p:editor value="#{disciplinaGSBean.disciplina.bibliografiaPrincipal}" width="800" maxlength="1000" /> 

                                </h:panelGrid>
                                <h:panelGrid columns="2" width="99%" style="text-align: center" >
                                    <h:outputText value="Upload do Plano de Curso: " style="width: 20%" />
                                    <h:form enctype="multipart/form-data" >
                                        <p:fileUpload fileUploadListener="#{disciplinaGSBean.doUploadPDF}" mode="advanced" label="Adicionar" update="messages" auto="true"  allowTypes="/(\.|\/)(pdf)$/" multiple="false" style="width: 80%;background-color: #E0E0E0" />  
                                        <p:growl id="messages" showDetail="true" escape="false"/>  
                                    </h:form>
                                </h:panelGrid>

                                <p:panel id="pCoord" header="Histórico de Professores" style="background-color: #D0D0D0;font-size: large " >

                                    <p:dataTable id="listaDocentes" var="docentes" value="#{autorBean.listaAutores}"   paginator="true" rows="15"  
                                                 selection="#{disciplinaGSBean.professorSelecionado}" 
                                                 emptyMessage="Não existem professores cadastrados que atendam esse critério" 
                                                 filteredValue="#{autorBean.filtroAutores}"> 


                                        <f:facet name="header">  
                                            Lista Docentes Disponíveis 
                                        </f:facet>  

                                        <p:column headerText="Nome" filterBy="nome" filterMatchMode="contains" style="width:25%;min-width: 25%;max-width: 25%;">  
                                            #{docentes.nome}    
                                        </p:column>  

                                        <p:column headerText="Instituição" filterBy="instituicaoAutor.nome" filterMatchMode="contains" style="text-align:center;min-width: 73%;max-width: 73%;white-space: normal;width:73%">  
                                            <h:outputText value="#{docentes.instituicaoAutor.nome} - #{docentes.instituicaoAutor.municipio}" />
                                        </p:column>  

                                        <p:column style="width:4%">  
                                            <p:commandButton action="#{disciplinaGSBean.addProfessor()}" id="selectButton" icon="ui-icon-plusthick" title="Add" update=":form:pDocCad">  
                                                <f:setPropertyActionListener value="#{docentes}" target="#{disciplinaGSBean.professorSelecionado}" />  
                                            </p:commandButton>  
                                        </p:column>  


                                    </p:dataTable>


                                    <br/><br/>

                                    <p:panel id="pDocCad"  header="Docentes cadastrados:" style="margin-bottom:10px;">

                                        <p:dataTable id="docentesCadastrados" var="docenteCad" value="#{disciplinaGSBean.disciplina.professores}">  

                                            <p:column headerText="Nome" style="width:46%;white-space: normal;">  
                                                <h:outputText value="#{docenteCad.ultimoNome}, #{docenteCad.restanteNome} " />  
                                            </p:column>  
                                            <p:column headerText="Intituição" style="width: 50%;white-space: normal;">
                                                <h:outputText value="#{docenteCad.instituicaoAutor.nome} - #{docenteCad.instituicaoAutor.municipio} " />
                                            </p:column>


                                            <p:column style="width:4%">  
                                                <p:commandButton action="#{disciplinaGSBean.removerProfessor()}" id="selectButton" icon="ui-icon-trash" title="Remover" update="docentesCadastrados">  
                                                    <f:setPropertyActionListener value="#{docenteCad}" target="#{disciplinaGSBean.professorSelecionado}" />  
                                                </p:commandButton>  
                                            </p:column>  

                                        </p:dataTable>  




                                    </p:panel>
                                    <br/><br/>
                                    <h:panelGrid columns="1" width="99%" style="text-align: center" >
                                        <h:outputText value="Outras Observações (Máximo de 1000 caracteres): " style="width: 100%" /> 
                                        <p:editor value="#{disciplinaGSBean.disciplina.observacoes}" width="800" maxlength="1000" /> 


                                    </h:panelGrid>    
                                </p:panel>


                                <br/><br/>





                            </p:panel>


                            <br/><br/>




                        </div>
                    </p:panel>
                    <h:panelGrid columns="2" width="99%"  style="text-align:center" >
                        <p:commandButton value="Cadastrar" action="#{disciplinaGSBean.cadastrar()}" update="form" />
                        <p:commandButton value="Cancelar" action="/indexSistema.xhtml" ajax="false" />
                    </h:panelGrid>



                </h:form>    
            </f:view>
        </ui:define>
    </ui:decorate>
</html>